package com.general.run.futrue;


import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;


public class CompletableFutureTest {


    public static void main(String[] args) {

        //没有返回值
        CompletableFuture<Void> ft1 = CompletableFuture.runAsync(() -> {
            System.out.println("t1:洗水壶");
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t1:洗水壶");
        });

        //有返回值
        CompletableFuture<String> ft2 = CompletableFuture.supplyAsync(() -> {
            System.out.println("t2:洗茶杯");
            System.out.println("t2:拿茶叶");
            System.out.println("t2:洗茶杯");
            return "龙井";
        });

        //任务3：任务1和任务2完成后执行：泡茶
        CompletableFuture<String> ft3 = ft1.thenCombine(ft2, (__,tf) -> {
            System.out.println("T3拿到茶叶"+tf);
            System.out.println("泡茶"+tf);
            return "上茶"+tf;
        });

        String join = ft3.join();
        System.out.println(join);
    }


}
